package com.yidu.hbats.action.Recovery;

import com.yidu.hbats.action.vo.RecoveryAtsSchemeVo;
import com.yidu.hbats.model.*;
import com.yidu.hbats.service.Recovery.RecoveryAtsSchemeAthleteService;
import com.yidu.hbats.service.Recovery.RecoveryAtsSchemeAuditService;
import com.yidu.hbats.service.Recovery.RecoveryAtsSchemeExpertService;
import com.yidu.hbats.service.Recovery.RecoveryAtsSchemeService;
import com.yidu.hbats.service.emp.AtsEmpAthleteService;
import com.yidu.hbats.service.emp.AtsEmpExpertService;
import com.yidu.springbootdemo.permission.domain.Tuser;
import com.yidu.utils.FileTools;
import com.yidu.utils.Message;
import com.yidu.utils.RedisUtil;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("RecoveryAtsSchemeController")
public class RecoveryAtsSchemeController {

    //方案信息接口
    @Resource
    public RecoveryAtsSchemeService recoveryAtsSchemeService;

    //运动员接口
    @Resource
    public AtsEmpAthleteService atsEmpAthleteService;

    //方案对应的运动员表接口
    @Resource
    public RecoveryAtsSchemeAthleteService recoveryAtsSchemeAthleteService;

    //专家信息接口
    @Resource
    public AtsEmpExpertService atsEmpExpertService;

    @Resource
    //专家咨询接口
    public RecoveryAtsSchemeExpertService recoveryAtsSchemeExpertService;

    @Resource
    //审核表接口
    public RecoveryAtsSchemeAuditService recoveryAtsSchemeAuditService;


    //文件上传管理工具
    @Resource
    FileTools fileTools;

    //二级缓存
    @Resource
    RedisUtil redisUtil;
    @ResponseBody
    @RequestMapping("selectAllRe")
    public Map<String,Object> selectAllRe(AtsScheme atsScheme, @RequestParam("page") Integer pageNum,
                                        @RequestParam("limit") Integer pageSize, HttpServletRequest request){
        Map<String,Object> map;
        map = new HashMap<>();
        Tuser user = (Tuser) request.getSession().getAttribute("user");
        List<AtsScheme> list=new ArrayList<>();
        int count=0;
        //判断用户表的外键关联为空，那就是超级管理员之类的，就可以查看所有
        //为1的是领导 为2的是教练员  为3的是专家 为4的是运动员
        if(user.getCompanyNum()=="2"||"2".equals(user.getCompanyNum())){
            //传入教练员的外键
            atsScheme.setCoachId(Integer.valueOf(user.getFilId()));
            list=recoveryAtsSchemeService.selectAllRe(atsScheme,pageNum,pageSize);
            count=recoveryAtsSchemeService.selectCountone(atsScheme);
        }else if(user.getCompanyNum()=="4"||"4".equals(user.getCompanyNum())){
            //传入运动员的外键查询
            atsScheme.setRemark(user.getFilId());
            list=recoveryAtsSchemeService.selectAthleteAllOnere(atsScheme,pageNum,pageSize);
            count=recoveryAtsSchemeService.selectAthleteAllCountOnere(atsScheme);
        }else if(user.getUserName().equals("admin")){
            //管理员查看所有
            list=recoveryAtsSchemeService.selectAllRe(atsScheme,pageNum,pageSize);
            count=recoveryAtsSchemeService.selectCountone(atsScheme);
        }else if(user.getCompanyNum()=="1"||"1".equals(user.getCompanyNum())){
            //领导查看 10 20 21状态的
            list=recoveryAtsSchemeService.selectAuditAllOne(atsScheme,pageNum,pageSize);
            switch (count = recoveryAtsSchemeService.selectCountone(atsScheme)) {
            }
        }else if((user.getCompanyNum() == "3") || "3".equals(user.getCompanyNum())){
            //专家查看
            atsScheme.setRemark(user.getFilId());
            list=recoveryAtsSchemeService.selectAuditAllOne(atsScheme,pageNum,pageSize);
            count=recoveryAtsSchemeService.selectCountone(atsScheme);
        }
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", count);
        map.put("data", list);
        return map;
    }

    /**
     * 运动营养方案
     * 查询所有  返回map
     * @param atsScheme
     * @param
     * @return
     *//*
    @RequestMapping("selectAll1")
    @ResponseBody
    public Map<String,Object> selectAll1(AtsScheme atsScheme, @RequestParam(required = false,defaultValue = "1",
            value="page") Integer pageNum, @RequestParam(required = false,defaultValue = "10",value="limit")
            Integer pageSize, HttpServletRequest request){
        Map<String,Object> map = new HashMap();

        Tuser user = (Tuser) request.getSession().getAttribute("user");
        //判断用户表的外键关联为空，那就是超级管理员之类的，就可以查看所有
        //为1的是领导 为2的是教练员  为3的是专家 为4的是运动员
        if(user.getCompanyNum()=="2"||"2".equals(user.getCompanyNum())){
            atsScheme.setCoachId(Integer.valueOf(user.getFilId()));
        }else if(user.getCompanyNum()=="4"||"4".equals(user.getCompanyNum())){
            atsScheme.setAthleteId(Integer.valueOf(user.getFilId()));
        }

        List<AtsScheme> list = nutritionAtsSchemeService.selectAll1(atsScheme,pageNum,pageSize);

        int count = nutritionAtsSchemeService.selectCount1(atsScheme);
        //int count = 10;
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", count);
        map.put("data", list);
        return map;
    }
*/

    /**
     * 新增
     * @param recoveryAtsSchemeVo
     * @return
     */
    @ResponseBody
    @RequestMapping("addOrupdate")
    public Message addOrupdate(RecoveryAtsSchemeVo recoveryAtsSchemeVo){
        if(recoveryAtsSchemeVo.getFileone().getOriginalFilename()!=null &&!"".equals(recoveryAtsSchemeVo.getFileone().getOriginalFilename())){
            try {
                String file1=fileTools.saveFile("recovery",recoveryAtsSchemeVo.getFileone());
                recoveryAtsSchemeVo.setFile1(file1);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if(recoveryAtsSchemeVo.getFiletwo().getOriginalFilename()!=null &&!"".equals(recoveryAtsSchemeVo.getFiletwo().getOriginalFilename())){
            try {
                String file2 = fileTools.saveFile("recovery",recoveryAtsSchemeVo.getFiletwo());
                recoveryAtsSchemeVo.setFile2(file2);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if(recoveryAtsSchemeVo.getFilethree().getOriginalFilename()!=null &&!"".equals(recoveryAtsSchemeVo.getFilethree().getOriginalFilename())){
            try {
                String file3=fileTools.saveFile("recovery",recoveryAtsSchemeVo.getFilethree());
                recoveryAtsSchemeVo.setFile3(file3);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        //id不为空是修改
        if((recoveryAtsSchemeVo.getSchemeId() != null) && !"".equals(recoveryAtsSchemeVo.getSchemeId())){
            recoveryAtsSchemeService.updateByPrimaryKeySelective(recoveryAtsSchemeVo);
        }else{//否则就是增加
            recoveryAtsSchemeService.insertSelective(recoveryAtsSchemeVo);
        }

        Message message=new Message();
        message.setNum(1);
        message.setMsg("成功");
        return message;
    }

    /**
     * 查询当前教练员的所有运动员
     * @param coachId 运动员id
     * @return
     */
    @ResponseBody
    @RequestMapping("checkboxselectAll")
    public List<AtsEmpAthlete> checkboxselectAll(int coachId){
        List<AtsEmpAthlete> list=atsEmpAthleteService.selectByCoachIdone(coachId);
        return list;
    }

    /**
     * 根据主键id查询所有
     * @param schemeId 方案主键id
     * @return
     */
    @ResponseBody
    @RequestMapping("findAll")
    public AtsScheme findAll(int schemeId){
        AtsScheme atsScheme=recoveryAtsSchemeService.findByIdOne(schemeId);
        return atsScheme;
    }

    /**
     * 根据方案id查运动员
     * @param schemeId 方案主键id
     * @return
     */
    @ResponseBody
    @RequestMapping("findByIdone")
    public List<AtsSchemeAthlete> findByIdone(int schemeId){
        List<AtsSchemeAthlete> list=recoveryAtsSchemeAthleteService.selectByIdone(schemeId);
        return list;
    }
    /**
     * 逻辑删除
     * @param schemeId 方案主键id
     * @return
     */
    @ResponseBody
    @RequestMapping("updateIsva")
    public Message updateIsva(int schemeId){
        Message message;
        message = new Message();
        if(!StringUtils.isEmpty(schemeId)){
            int rows;
            rows = recoveryAtsSchemeService.updateByPrimaryKeySelectiveone(schemeId);
            if(rows>0){
                message.setNum(1);
                message.setMsg("删除成功!");
            }else{
                message.setNum(1);
                message.setMsg("操作失败!");
            }
        }
        return message;
    }

    /**
     * 批量删除
     * @param schemeId 方案主键id
     * @return
     */
    @ResponseBody
    @RequestMapping("deleteAllone")
    public Message deleteAllone(String schemeId){
        Message message=new Message();
        if(!StringUtils.isEmpty(schemeId)){
            String[] arr;
            arr = schemeId.split(",");
            int one;
            one = 0;
            for (int i = 0; i < arr.length; i++) {
                one++;
                int rows;
                rows = recoveryAtsSchemeService.updateByPrimaryKeySelectiveone(Integer.valueOf(arr[i]));
                //选择行数大于0删除成功
                if(!(rows <= 0)){
                    message.setNum(1);
                    message.setMsg("删除成功!删除了"+one+"行!");
                }else{//否则删除失败
                    message.setNum(1);
                    message.setMsg("操作失败!");
                }
            }
        }
        return message;
    }

    /**
     * 查询所有有效的专家
     * @return
     */
    @ResponseBody
    @RequestMapping("findAlltwo")
    public List<AtsEmpExpert> findAlltwo(){
        List<AtsEmpExpert> list=atsEmpExpertService.findAllFour();
        return list;
    }

    /**
     * 方案表
     * 根据id查询所有
     * @param schemeId
     * @return
     */
    @ResponseBody
    @RequestMapping("selectByPrimaryKeyOne")
    public AtsScheme selectByPrimaryKeyOne(int schemeId){
        AtsScheme atsScheme=recoveryAtsSchemeService.selectByPrimaryKey(schemeId);
        return atsScheme;
    }

    /**
     *
     * 新增
     * @param atsSchemeAudit 审核表
     * @param expertId
     * @param applyForExp
     * @return
     */
    @ResponseBody
    @RequestMapping("expertone")
    public Message expertone(AtsSchemeAudit atsSchemeAudit,int expertId,String applyForExp){
        AtsEmpExpert atsScheme;
        atsScheme = atsEmpExpertService.selectByPrimaryKey(expertId);
        int rows;
        rows = recoveryAtsSchemeAuditService.insertSelective(atsSchemeAudit);
        Message message;
        message = new Message();
        if(rows>0){
            AtsSchemeExpert atsSchemeExpert;
            atsSchemeExpert = new AtsSchemeExpert();
            //传入专家名字
            atsSchemeExpert.setExpertName(atsScheme.getExpertName());
            //传入专家id
            atsSchemeExpert.setExpertId(atsScheme.getExpertId().toString());
            //传入方案主键
            atsSchemeExpert.setSchemeId(Integer.valueOf(atsSchemeAudit.getSaId()));
            //传入方案名字
            atsSchemeExpert.setSaName(atsSchemeAudit.getSaName());
            //传入申请专家理由
            atsSchemeExpert.setApplyForExp(applyForExp);

            Date date = new Date();//获取当前的日期
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
            String str = df.format(date);//获取String类型的时间
            Date utilDate = new Date();//util.Date
            java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
            //传入创建时间
            atsSchemeExpert.setCreatTime(sqlDate);
            //默认传入10为咨询状态
            atsSchemeExpert.setAuditState("10");
            //传入创建人
            atsSchemeExpert.setCreater(atsSchemeAudit.getCreater());
            //默认传入1为有效
            atsSchemeExpert.setIsva(1);
            //传入申请咨询时间
            atsSchemeExpert.setApplyForTime(str);
            recoveryAtsSchemeExpertService.insertSelective(atsSchemeExpert);
        }
        message.setNum(1);
        message.setMsg("操作成功!");
        return message;
    }

    /**
     * 查询是否已经提交审核和专家申请
     * @param schemeId
     * @return
     */
    @ResponseBody
    @RequestMapping("selectState")
    public Message selectState(int schemeId){
        Message message=new Message();
        int rows;
        rows = recoveryAtsSchemeExpertService.selectByOne(schemeId);
        if(!(rows <= 0)){
            message.setNum(1);
            message.setMsg("审核和申请已经提交过，是否修改");
        }else{
            message.setNum(0);
        }
        return message;
    }

    @ResponseBody
    @RequestMapping("selectBySix")
    public AtsSchemeExpert selectBySix(Integer schemeId){
        AtsSchemeExpert atsSchemeExpert=recoveryAtsSchemeExpertService.selectBySix(schemeId);
        return atsSchemeExpert;
    }

    /**
     * 修改申请和咨询
     * @param applyForExp 申请理由
     * @param expertId  主键id
     * @param saName  方案名称
     * @param saId  方案外键
     * @return 返回一个提示工具类
     */
    @ResponseBody
    @RequestMapping("updateState")
    public Message updateState(String applyForExp,int expertId,String saName,int saId){
        //根据传过来的专家主键查询
        AtsEmpExpert atsScheme;
        atsScheme = atsEmpExpertService.selectByPrimaryKey(expertId);
        Message message;
        message = new Message();
        if(!StringUtils.isEmpty(expertId)){
            //new出审核表模型
            AtsSchemeAudit atsSchemeAudit;
            atsSchemeAudit = new AtsSchemeAudit();
            //传入方案名称参数
            atsSchemeAudit.setSaName(saName);
            //传入方案id参数，要根据id修改
            atsSchemeAudit.setSaId(Integer.valueOf(saId).toString());
            Date utilDate = new Date();//util.Date
            java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
            //传入创建时间
            atsSchemeAudit.setCreatTime(sqlDate);
            recoveryAtsSchemeAuditService.updateByPrimaryKeySelectivetwo(atsSchemeAudit);
            //new出专家咨询表模型
            AtsSchemeExpert atsSchemeExpert=new AtsSchemeExpert();
            Date utilDateone = new Date();//util.Date
            java.sql.Date sqlDateone = new java.sql.Date(utilDateone.getTime());
            //传入创建时间
            atsSchemeExpert.setCreatTime(sqlDateone);
            //传入方案名称
            atsSchemeExpert.setSaName(saName);
            //传入申请理由
            atsSchemeExpert.setApplyForExp(applyForExp);
            //传入申请时间
            Date date = new Date();//获取当前的日期
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
            String str = df.format(date);//获取String类型的时间
            atsSchemeExpert.setApplyForTime(str);
            //传入方案外键根据它来修改
            atsSchemeExpert.setSchemeId(saId);
            //传入专家外键
            atsSchemeExpert.setExpertId(atsScheme.getExpertId().toString());
            //传入专家名字
            atsSchemeExpert.setExpertName(atsScheme.getExpertName());
            recoveryAtsSchemeExpertService.updateByPrimaryKeySelectiveone(atsSchemeExpert);
            message.setNum(1);
            message.setMsg("提交成功!");
        }
        return message;
    }

    /**
     * 查询所有带分页
     * @param atsSchemeAudit 审核表
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping("selectStateAll")
    public Map<String,Object> selectStateAll(AtsSchemeAudit atsSchemeAudit,@RequestParam("page") Integer pageNum, @RequestParam("limit") Integer pageSize){
        System.out.println(pageNum+"    "+pageSize);
        Map<String,Object> map=new HashMap<>();
        List<AtsSchemeAudit> list;
        list = recoveryAtsSchemeAuditService.selectByPrimaryKeyTwowx(atsSchemeAudit,pageNum,pageSize);
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", recoveryAtsSchemeAuditService.selectByPrimaryKeyCountTwowx(atsSchemeAudit));
        map.put("data", list);
        return map;
    }

    /**
     *
     * @param atsSchemeAudit
     * @param yesOrno
     * @return
     */
    @ResponseBody
    @RequestMapping("auditUpdate")
    public Message auditUpdate(AtsSchemeAudit atsSchemeAudit,int yesOrno){
        //传入审核状态
        atsSchemeAudit.setAuditState(String.valueOf(yesOrno));
        Date date = new Date();//获取当前的日期
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String str = df.format(date);//获取String类型的时间
        //传入审核时间
        atsSchemeAudit.setAuTime(str);
        Message message=new Message();
        int rows=recoveryAtsSchemeAuditService.updateByPrimaryKeySelectivethree(atsSchemeAudit);
        if(rows>0){
            AtsSchemeExpert atsSchemeExpert;
            atsSchemeExpert = new AtsSchemeExpert();
            //传入方案主键
            atsSchemeExpert.setSchemeId(Integer.valueOf(atsSchemeAudit.getSaId()));
            //传入审核状态
            atsSchemeExpert.setAuditState(String.valueOf(yesOrno));
            recoveryAtsSchemeExpertService.updateByPrimaryKeySelectiveThree(atsSchemeExpert);
            message.setMsg("操作成功!");
            message.setNum(1);
        }
        return message;
    }

    /**
     *
     * @param schemeId
     * @return
     */
    @ResponseBody
    @RequestMapping("selectAudit")
    public AtsSchemeAudit selectAudit(int schemeId){
        AtsSchemeAudit atsSchemeAudit=recoveryAtsSchemeAuditService.selectBySchemeIdFour(schemeId);
        return atsSchemeAudit;
    }

    /**
     *
     * @param schemeId
     * @return
     */
    @ResponseBody
    @RequestMapping("selectAuditcount")
    public Message selectAuditcount(int schemeId){
        Message message=new Message();
        int rows=recoveryAtsSchemeAuditService.selectByPrimaryKeyCountThree(schemeId);
        if(!(rows <= 0)){
            message.setNum(1);
        }else{
            message.setNum(0);
        }
        return message;
    }

    @ResponseBody
    @RequestMapping("selectExperttwo")
    public Map<String,Object> selectExpert(HttpSession session, AtsSchemeExpert atsSchemeExpert, @RequestParam("page") Integer pageNum, @RequestParam("limit") Integer pageSize){
        Map<String,Object> map=new HashMap<>();
        Tuser user = (Tuser) session.getAttribute("user");
        atsSchemeExpert.setExpertId(user.getFilId());
        List<AtsSchemeExpert> list=recoveryAtsSchemeExpertService.findAllSIxre(atsSchemeExpert,pageNum,pageSize);
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", recoveryAtsSchemeExpertService.countSIxre(atsSchemeExpert));
        map.put("data", list);
        return map;
    }

    /**
     * 查询专家回复
     * @param seId
     * @return
     */
    @ResponseBody
    @RequestMapping("selectExpertState")
    public AtsSchemeExpert selectExpertState(int seId){
        AtsSchemeExpert atsSchemeExpert=recoveryAtsSchemeExpertService.selectByPrimaryKeyFour(seId);
        return atsSchemeExpert;
    }


    @ResponseBody
    @RequestMapping("updateExpertState")
    public  Message updateExpertState(int schemeId){
        Message message;
        message = new Message();
        AtsSchemeExpert atsSchemeExpert=new AtsSchemeExpert();
        atsSchemeExpert.setSchemeId(schemeId);
        atsSchemeExpert.setAuditState("30");
        int rows=recoveryAtsSchemeExpertService.updateByPrimaryKeySelectiveThree(atsSchemeExpert);
        if(!(rows <= 0)){
            AtsSchemeAudit atsSchemeAudit;
            atsSchemeAudit = new AtsSchemeAudit();
            atsSchemeAudit.setSaId(String.valueOf(schemeId));
            atsSchemeAudit.setAuditState("30");
            recoveryAtsSchemeAuditService.updateByPrimaryKeySelectiveFour(atsSchemeAudit);
            message.setNum(1);
            message.setMsg("已成专家已获知待回复!");
        }
        return message;
    }
    @ResponseBody
    @RequestMapping("updateResules")
    public Message updateResules(int schemeId,String results){
        Message message;
        message = new Message();
        AtsSchemeExpert atsSchemeExpert=new AtsSchemeExpert();
        atsSchemeExpert.setSchemeId(schemeId);
        atsSchemeExpert.setResults(results);
        atsSchemeExpert.setAuditState("40");
        int rows;
        rows = recoveryAtsSchemeExpertService.updateByPrimaryKeySelective(atsSchemeExpert);
        if(!(rows <= 0)){
            AtsSchemeAudit atsSchemeAudit=new AtsSchemeAudit();
            atsSchemeAudit.setSaId(String.valueOf(schemeId));
            atsSchemeAudit.setAuditState("40");
            recoveryAtsSchemeAuditService.updateByPrimaryKeySelectiveFour(atsSchemeAudit);
            message.setMsg("您的反馈消息已提交!");
            message.setNum(1);
        }
        return message;
    }
    @ResponseBody
    @RequestMapping("addScheme")
    public Message addScheme(String resultEffect,String resultExp,int schemeId,@RequestParam(value = "fileone", required = false) MultipartFile fileone){
        Message message;
        message = new Message();
        AtsScheme atsScheme;
        atsScheme = new AtsScheme();
        if((fileone.getOriginalFilename() != null) && !"".equals(fileone.getOriginalFilename())){
            try {
                String file1=fileTools.saveFile("TrainingPlan",fileone);
                atsScheme.setResultFile(file1);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        Date date = new Date();//获取当前的日期
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String str = df.format(date);//获取String类型的时间
        atsScheme.setResultTime(str);
        atsScheme.setSchemeId(schemeId);
        atsScheme.setResultEffect(resultEffect);
        atsScheme.setResultExp(resultExp);
        int rows=recoveryAtsSchemeService.updateByPrimaryKeySelective(atsScheme);
        if(!(rows <= 0)){
            message.setNum(1);
            message.setMsg("反馈成功!");
        }
        return message;
    }
    @ResponseBody
    @RequestMapping("findResults")
    public AtsScheme findResults(int schemeId){
        AtsScheme atsScheme=recoveryAtsSchemeService.findByIdOne(schemeId);
        return atsScheme;
    }
    @ResponseBody
    @RequestMapping("findstateOne")
    public AtsSchemeExpert findstateOne(int schemeId){
        AtsSchemeExpert atsSchemeExpert=recoveryAtsSchemeExpertService.selectByPrimaryKeyFive(schemeId);
        return atsSchemeExpert;
    }

    /**
     * 中心领导不同意后，继续上传方案
     * @param schemeId 方案主键
     * @param applyForExp 申请理由
     * @param expertId 专家id
     * @param saName 方案名称
     * @return
     */
    @ResponseBody
    @RequestMapping("updateStateTwo")
    public Message updateState(Integer schemeId,String applyForExp,Integer expertId,String saName) {
        //根据传过来的专家主键查询
        AtsEmpExpert atsScheme;
        atsScheme = atsEmpExpertService.selectByPrimaryKey(expertId);
        Message message;
        message = new Message();
        AtsSchemeAudit atsSchemeAudit;
        atsSchemeAudit = new AtsSchemeAudit();
        atsSchemeAudit.setAuditState("10");
        atsSchemeAudit.setSaId(String.valueOf(schemeId));
        int rows;
        rows = recoveryAtsSchemeAuditService.updateByPrimaryKeySelectivethree(atsSchemeAudit);
        if (!(rows <= 0)) {
            AtsSchemeExpert atsSchemeExpert = new AtsSchemeExpert();
            //传入查出来专家名字
            atsSchemeExpert.setExpertName(atsScheme.getExpertName());
            //传入传过来的专家Id
            atsSchemeExpert.setExpertId(String.valueOf(expertId));
            //传入方案Id
            atsSchemeExpert.setSchemeId(schemeId);
            //传入状态为10
            atsSchemeExpert.setAuditState("10");
            //util.Date
            Date utilDateone = new Date();
            java.sql.Date sqlDateone = new java.sql.Date(utilDateone.getTime());
            //传入创建时间
            atsSchemeExpert.setCreatTime(sqlDateone);
            //传入方案名称
            atsSchemeExpert.setSaName(saName);
            //传入申请理由
            atsSchemeExpert.setApplyForExp(applyForExp);
            //传入申请时间
            Date date = new Date();//获取当前的日期
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
            String str = df.format(date);//获取String类型的时间
            atsSchemeExpert.setApplyForTime(str);
            //执行修改专家咨询表的方法
            recoveryAtsSchemeExpertService.updateByPrimaryKeySelectiveone(atsSchemeExpert);
            message.setNum(1);
            message.setMsg("操作成功!");
        }
        return message;
    }
    /**
     * 根据教练员外键 修改是否查看
     * @param session
     * @param atsSchemeAthlete  运动员关联表对象
     * @return
     */
    @ResponseBody
    @RequestMapping("addExp")
    public Message message(HttpSession session,AtsSchemeAthlete atsSchemeAthlete){
        Message message;
        message = new Message();
        Tuser user = (Tuser) session.getAttribute("user");
        if("4".equals(user.getCompanyNum())){
            atsSchemeAthlete.setAthleteId(Integer.valueOf(user.getFilId()));
            int rows=recoveryAtsSchemeAthleteService.updateByPrimaryKeySelectiveZero(atsSchemeAthlete);
            if(rows>0){
                message.setNum(1);
                message.setMsg("操作成功！");
            }
            return message;
        }
        return null;
    }

    /**
     * 根据方案id查询运动员
     * @param schemeId  方案id
     * @return
     */
    @ResponseBody
    @RequestMapping("selectAthleteById")
    public List<AtsSchemeAthlete> selectAthleteById(Integer schemeId){
        List<AtsSchemeAthlete> atsSchemeAthlete=recoveryAtsSchemeAthleteService.selectByIdone(schemeId);
        return atsSchemeAthlete;
    }

    /**
     * 根据方案id 查询审核状态
     * @param saId 方案id
     * @return
     */
    @ResponseBody
    @RequestMapping("selectBySaId")
    public AtsSchemeAudit selectBySaId(Integer saId){
        AtsSchemeAudit atsSchemeAthlete=recoveryAtsSchemeAuditService.selectBySchemeIdFour(saId);
        return atsSchemeAthlete;
    }

    /**
     * 根据方案id 查询专家
     * @param schemeId 方案id
     * @return
     */
    @ResponseBody
    @RequestMapping("selectAuExp")
    public AtsSchemeExpert selectAuExp(Integer schemeId){
        AtsSchemeExpert atsSchemeExpert=recoveryAtsSchemeExpertService.selectByPrimaryKeyFive(schemeId);
        return atsSchemeExpert;
    }
}
